'use strict'

define(['jquery', 'bootstrap', 'select2', 'validate', 'validate.en', 'koala-search', 
        'modalSearch', 'datetimepicker', 'datetimepickerCN', 'shiftform'], function ($, validate) {
  
  return {

    init: function (data) {
      
      this.data = data;
      this.existCode = false;
      this.existCitizen = false;
      this.existMobile = false;
      
      this.initEdit();
      this.initPage();
      this.exist();
      
    },

    initEdit: function () {
      
      var that = this;

      $(document).find('form').bt_validate();

      $('select[name="gender"]').select2({
        placeholder: '请选择',
        minimumResultsForSearch: -1,
        allowClear: true,
      });

      $('select[name="educationLevel"]').select2({
        placeholder: '请选择',
        minimumResultsForSearch: -1,
        allowClear: true,
      });

      $('select[name="dutyId"]').select2({
        placeholder: '请选择',
        minimumResultsForSearch: -1,
        allowClear: true,
      });

      $('select[name="clanId"]').select2({
        placeholder: '请选择',
        minimumResultsForSearch: -1,
        allowClear: true,
      });

      $('select[name="degreeId"]').select2({
        placeholder: '请选择',
        minimumResultsForSearch: -1,
        allowClear: true,
      });
      
      $('select[name=drivingType]').select2({
        placeholder: '请选择',
        minimumResultsForSearch: -1,
        allowClear: true,
      });
      
      $('select[name="contractParty"]').select2({
        placeholder: '请选择',
        minimumResultsForSearch: -1,
        allowClear: true
      });
      
      $('select[name=active]').select2({
        placeholder: '请选择',
        minimumResultsForSearch: -1,
        allowClear: true,
      });
      
      $('select[name=status]').select2({
        placeholder: '请选择',
        minimumResultsForSearch: -1,
        allowClear: true,
      });
      
      $('select[name=disabled]').select2({
        placeholder: '请选择',
        minimumResultsForSearch: -1,
        allowClear: true,
      });
      
      $(document).on('click', 'button.btn-submit', function(e) {
        
        if (that.existCode || that.existCitizen || that.existMobile) {
          return false;
        } else {
          return true;
        }
        
      });
      
    },
    
    initPage: function () {

    	$('.date').datetimepicker({
        format: 'yyyy-mm-dd',
        autoclose: true,
        language: 'zh-CN',
        todayBtn: 'linked',
        startDate: '${today}',
        todayHighlight: true,
        pickerPosition: 'bottom-right',
        minView: 'month'
      });

    	$('[data-target="#modal-search-vehicle"]').modalsearch({
        url: function () {
          var url = window.__CTX__.root + '/vehicles/query';
          return url + "?companyIds=" + $("input[name='organizationId']").val();
        },
        tableColumns: ['驳运车代码', '驳运车名称'],
        tableValues: ['code', 'name'],
        displayValues: ['code', 'name'],
        values: ['id']
      });

      var options = {
        time: 1000,
        url: window.__CTX__.root + "/vehicles/query",
        queryName: "code",
        value: ["id"],
        display: ["code", "name"]
      }
      $('.vehicle-search').koalaSearch(options);
      	
      $('form').bt_validate()  //bind validate
      
    },
    
    
    
  }
})